﻿using exMath.Sequences;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace exMath.Test
{
    
    
    /// <summary>
    ///This is a test class for FibonacciSequenceTest and is intended
    ///to contain all FibonacciSequenceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FibonacciSequenceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Reset
        ///</summary>
        [TestMethod()]
        public void ResetTest()
        {

            //setup the object + generate data
            FibonacciSequence target = new FibonacciSequence();
            target.Next();
            target.Next();
            target.Next();
            target.Next();
            target.Next();
            target.Next();

            Assert.AreEqual(5.0, target.Current);

            //test the reset functionality.

            target.Reset();

            Assert.AreEqual(0.0, target.Current);
            
            //check if the sequence object is reinitialized properly.
            target.Next();
            target.Next();
            target.Next();
            target.Next();
            target.Next();

            Assert.AreEqual(3.0, target.Current);
        }

        /// <summary>
        ///A test for Next
        ///</summary>
        [TestMethod()]
        public void NextTest()
        {
            FibonacciSequence target = new FibonacciSequence();
            List<double> results = new List<double>();

            //generate some fibonacci numbers.
            target.Next();
            results.Add(target.Current);
            target.Next();
            results.Add(target.Current);
            target.Next();
            results.Add(target.Current);
            target.Next();
            results.Add(target.Current);
            target.Next();
            results.Add(target.Current);
            target.Next();
            results.Add(target.Current);

            Assert.AreEqual(2.0, results[3]);
            Assert.AreEqual(3.0, results[4]);
            Assert.AreEqual(5.0, results[5]);
        }

        /// <summary>
        ///A test for CalculateItemN
        ///</summary>
        [TestMethod()]
        public void CalculateItemNTest()
        {
            FibonacciSequence target = new FibonacciSequence();
            double result = target.CalculateItemN(3);
            double result2 = target.CalculateItemN(4);
            double result3 = target.CalculateItemN(5);

            Assert.AreEqual(2.0, result);
            Assert.AreEqual(3.0, result2);
            Assert.AreEqual(5.0, result3);   
        }
    }
}
